

#自定义过滤规则
from django_filters.rest_framework import FilterSet,filters
from rest_framework.filters import BaseFilterBackend
from . import models

class MyFilter(BaseFilterBackend):
    def filter_queryset(self, request, queryset, view):
        #真正的过滤规则
        # params = request.GET.get('teacher')
        # queryset.filter('')
        return queryset[:1]

#借助django_filter区间过滤
class CourseFilterSet(FilterSet):
    #课程的价格范围要大于min_price，小于max_price
    min_price = filters.NumberFilter(field_name='price', lookup_expr='gt')
    max_price = filters.NumberFilter(field_name='price', lookup_expr='lt')
    class Meta:
        model = models.Course
        fields = ['course_category']








